
package com.netease.xone.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.netease.log.NTLog;
import com.netease.pkgRelated.XoneConsts;
import com.netease.xone.R;
import com.netease.xone.fragment.FragmentSearch;
import com.netease.xone.fragment.FragmentSearch.Searchable;
import com.netease.xone.fragment.FragmentSubjectAndSourceList;

public class ActivitySearch extends ActivityX1Base implements Searchable {

    /**
     * @param context
     * @param type：{@link FragmentSearch.TYPE_SQUARE}，
     *            {@link FragmentSearch.TYPE_SUBSCRIBE}
     */
    public static void startActivity(Context context, int type) {
        Intent i = new Intent(context, ActivitySearch.class);
        i.putExtra(XoneConsts.BUNDLE_KEY.SEARCH_UI_TYPE, type);
        context.startActivity(i);
    }

    public static final String TAG = "ActivitySearch";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_container);
        int type = getIntent().getIntExtra(XoneConsts.BUNDLE_KEY.SEARCH_UI_TYPE,
                FragmentSearch.TYPE_SUBSCRIBE);
        if (findViewById(R.id.fragment_container) != null) {
            if (savedInstanceState != null) {
                return;
            }
            FragmentSearch fragment = FragmentSearch.newInstance(type);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, fragment).commit();
        }
    }

    @Override
    public void doSearch(int type, String searchString) {
        switch (type) {
            case XoneConsts.SEARCH_TYPE.INFO:
                NTLog.i(TAG, "do search INFO:" + searchString);
                break;
            case XoneConsts.SEARCH_TYPE.USER:
                NTLog.i(TAG, "do search USER:" + searchString);
                break;
            case XoneConsts.SEARCH_TYPE.SOURCE:
                NTLog.i(TAG, "do search SOURCE:" + searchString);
                break;
            case XoneConsts.SEARCH_TYPE.SUBJECT_AND_SOURCE:
                NTLog.i(TAG, "do search SUBJECT_AND_SOURCE:" + searchString);
                FragmentSubjectAndSourceList fragment = FragmentSubjectAndSourceList
                        .newInstance(searchString);
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.fragment_container, fragment).addToBackStack(null).commit();
                break;
        }
    }

}
